import * as type from './type'
import http from 'Utils/http'

const actions = {
    // 请求商品列表
    async getGoodsList({ commit }, value) {
        if (!value.sort) {
            const result = await http('/jianke/searchs', {
                cid: value.cid,
                pn: value.pn,
                ps: value.ps,
            })
            let actions = {
                type: type['GOODSLIST'],
                payload: result
            }
            commit(actions)
        } else {
            const result = await http('/jianke/searchs', {
                cid: value.cid,
                pn: value.pn,
                ps: value.ps,
                sort: value.sort
            })
            let actions = {
                type: type['GOODSLIST'],
                payload: result
            }
            commit(actions)
        }
    },
    // 清空商品列表
    async clearGoodsList({ commit }) {
        let actions = {
            type: type['CLEAR']
        }
        commit(actions)
    }
}

export default actions